home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17835 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  73 lines

  1. Path: mail2news.demon.co.uk!j-bg.demon.co.uk
  2. From: John Sargent <jb@j-bg.demon.co.uk>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: main()
  5. Date: Wed, 17 Apr 96 18:42:21 GMT
  6. Message-ID: <829766541snz@j-bg.demon.co.uk>
  7. References: <3174c0dc.7652220@news.flex.com.au>
  8. Reply-To: jb@j-bg.demon.co.uk
  9. X-NNTP-Posting-Host: j-bg.demon.co.uk
  10. X-Newsreader: Demon Internet Simple News v1.29
  11. X-Mail2News-Path: j-bg.demon.co.uk
  12.  
  13. In article <3174c0dc.7652220@news.flex.com.au>
  14.            cobweb@flex.com.au "Tony L" writes:
  15.  
  16. > Hi all,
  17. > I have come across two different ways that 2 different beginners books
  18. > recommend that every program should start.  Could someone please tell
  19. > me which one is the "BEST" or proper way?
  20. > #include <stdio.h>
  21. > void main()
  22. > {
  23. >         printf("Hello!\n");
  24. >         return 0;
  25. > }
  26.  
  27. This is plain wrong. You are trying to return a value ( 0 ) from a function
  28. that doesn't return a value.
  29.  
  30.  
  31.  
  32. > Or, the same as above but not include "void":
  33. > #include <stdio.h>
  34. > main()
  35. > {
  36. >         printf("Hello!\n");
  37. >         return 0;
  38. > }
  39.  
  40. If you don't specify a return type, the compiler assumes that you mean
  41. type int.
  42.  
  43.  
  44. I would use...
  45.  
  46.  
  47. #include <stdio.h>
  48. void main(void)
  49. {
  50.     printf("Hello!\n");
  51.     return;
  52. }
  53.  
  54. or
  55.  
  56. #include <stdio.h>
  57. int main(void)
  58. {
  59.     printf("Hello!\n");
  60.     return 0;
  61. }
  62.  
  63.  
  64. I personally don't like the parameter list left blank (except in class 
  65. constructors etc.)
  66.  
  67.  
  68. Regards,
  69. John Sargent
  70.